<?php

namespace EmailDelivery\Templates\EmailVerify;

use Users\Profile;
/**
 * Created by ITokarev
 * 
 * Recover Email Delivery Template
 */

class TemplateAction extends \Action
{
	
	protected static $layout = '#emailDelivery.templates.layout';
	 
	public function run()
	{	
		$profile = Profile::find($this->request->userId);
		
		if (!$this->request->email && !$profile)
		{
			throw new \Exception('Email or Profile Not Found', 500);
		}
		
		$userName = $this->request->userName ? $this->request->userName : $profile->nickname;
		$this->response->userName = $userName;
		
		$this->response->profile = $profile;
		$code = $this->request->code ? $this->request->code : $profile->generateVerifyCode();
		$this->response->code = $code;
				
		$this->response->email = $this->request->email;

		$this->response->set('title', 'Verify Code');
		$this->response->set('to', $this->request->email);
	}
}